use std::fmt::{self, Display, Formatter};
use tge::util::Rect;

#[derive(Debug)]
pub struct Block {
    pub grid: [[u8; 5]; 5],
    pub rect: Rect,
}

#[allow(dead_code)]
pub enum Diffculty {
    Easy,
    Medium,
    Hard,
    HardEx,
    BigBlock,
    Bar,
    Flat,
    Good,
}

impl Display for Block {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        let mut sd: String = "".to_owned();
        for i in 0..5 {
            for j in 0..5 {
                if self.grid[j][i] != 0 {
                    sd.push_str("[]");
                } else {
                    sd.push_str("  ");
                }
            }
            sd.push_str("\n");
        }
        write!(f, "{}{:?}", sd, self.rect)
    }
}

pub fn get_blocks(diff: Diffculty) -> Vec<u8> {
    match diff {
        Diffculty::Easy => {
            return vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
        }
        Diffculty::Medium => {
            return vec![
                12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
            ];
        }
        Diffculty::Hard => {
            return vec![33, 34, 35, 36, 37, 38, 41];
        }
        Diffculty::HardEx => {
            return vec![42, 43, 44, 45, 46, 47, 48, 49, 50];
        }
        Diffculty::BigBlock => {
            return vec![39, 40, 41];
        }
        Diffculty::Bar => {
            return vec![6, 7, 14, 15, 33, 34];
        }
        Diffculty::Flat => {
            return vec![
                2, 3, 6, 7, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
                32, 33, 34,
            ];
        }
        Diffculty::Good => {
            return vec![2, 3, 6, 7, 14, 15, 16, 22, 24, 26, 28];
        }
    }
}

pub const BLOCKS: [Block; 50] = [
    //1
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 2,
            height: 1,
            width: 1,
        },
    },
    //2
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 2,
            height: 1,
            width: 2,
        },
    },
    //3
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 2,
            height: 2,
            width: 1,
        },
    },
    //4
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 2,
            height: 2,
            width: 2,
        },
    },
    //5
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 2,
            width: 2,
        },
    },
    //6
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 1,
            width: 3,
        },
    },
    //7
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 1,
            height: 3,
            width: 1,
        },
    },
    //8
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 1,
            height: 2,
            width: 2,
        },
    },
    //9
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 2,
        },
    },
    //10
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 2,
        },
    },
    //11
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 2,
        },
    },
    //12
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //13
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //14
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 1],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 1,
            width: 4,
        },
    },
    //15
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 1,
            height: 4,
            width: 1,
        },
    },
    //16
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 1,
            height: 2,
            width: 2,
        },
    },
    //17
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 3,
        },
    },
    //18
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //19
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 2,
            width: 3,
        },
    },
    //20
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //21
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //22
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 2,
            width: 3,
        },
    },
    //23
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //24
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 3,
        },
    },
    //25
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //26
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 3,
        },
    },
    //27
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //28
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 2,
            width: 3,
        },
    },
    //29
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //30
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 2,
            width: 3,
        },
    },
    //31
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //32
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 1, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 2,
            height: 2,
            width: 3,
        },
    },
    //33
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [1, 1, 1, 1, 1],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 0,
            y: 2,
            height: 1,
            width: 5,
        },
    },
    //34
    Block {
        grid: [
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
        ],
        rect: Rect {
            x: 2,
            y: 0,
            height: 5,
            width: 1,
        },
    },
    //35
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //36
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //37
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //38
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //39
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 3,
        },
    },
    //40
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //41
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //42
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //43
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //44
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //45
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
    //46
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 0, 1, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 3,
        },
    },
    //47
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //48
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 1, 0, 1, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 2,
            width: 3,
        },
    },
    //49
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 2,
        },
    },
    //50
    Block {
        grid: [
            [0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 1, 1, 1, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0],
        ],
        rect: Rect {
            x: 1,
            y: 1,
            height: 3,
            width: 3,
        },
    },
];
